package cn.edu.nju.software.cdiy.action.user.login;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import cn.edu.nju.software.cdiy.bean.Scheme;
import cn.edu.nju.software.cdiy.bean.User;
import cn.edu.nju.software.cdiy.service.UserService;
import cn.edu.nju.software.cdiy.util.BusinessConstant;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class UserSchemeAction extends ActionSupport implements SessionAware, ServletResponseAware {

	private Map<String, Object> session;
	private HttpServletResponse response;
	private UserService userService;
	private List<Scheme> schemeList;

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
		this.response.setCharacterEncoding("UTF-8");
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public List<Scheme> getSchemeList() {
		return schemeList;
	}

	@Override
	public String execute() throws Exception {
		User user = (User) session.get(BusinessConstant.S_USER);
		schemeList = userService.getUserSchemes(user.getId());
		return SUCCESS;
	}
	
	public void delete() throws Exception {
		response.getWriter().write("删除成功！");
	}

}
